function [HammingLoss, HammingLossBefore, RecoveredTrueLabel] = Ddavid_recover_multi_label(Data, TrueLabel, SampledTrueLabel, K, KNNList, R, T, Method)

% [HammingLoss, HammingLossBefore, RecoveredTrueLabel] = Ddavid_recover_multi_label(Data, TrueLabel, SampledTrueLabel, K, KNNList, R, T, Method)
%
% <Input>
% Data: [n*m], n is the number of instances, m is the number of features
% TrueLabel: [n*k], the value is {-1, 1}, the real answer of labels, k is
%                   the number of labels
% SampledTrueLabel: [n*k], the value is {-1, 1}, the sampled labels
% K: The K value of KNN
% KNNList: The KNN List (for saving time)
% R: double, the relaxation parameter, R >= 0
% T: integer, the max relaxation times
% Method: integer, the choice of the single recovering method
%
% <Output>
% HammingLoss: double, the hamming loss
% HammingLossBefore: double, the hamming loss bebore this process
% RecoveredTrueLabel: [n*k], the value is {-1, 1}

HammingLossBefore = Hamming_loss(SampledTrueLabel, TrueLabel);
RecoveredTrueLabel = zeros(size(SampledTrueLabel, 1), size(SampledTrueLabel, 2));

LabelSize = size(SampledTrueLabel, 2);

for LabelIndex = 1:LabelSize
    disp(['# Label ' num2str(LabelIndex) ' Size = ' num2str(sum(SampledTrueLabel(:, LabelIndex) == 1))]);
    if(sum(SampledTrueLabel(:, LabelIndex) == 1) == 0)
        RecoveredTrueLabel(:, LabelIndex) = ones(size(Data, 1), 1) * (-1);
    else
        switch(Method)
            case 1
                RecoveredTrueLabel(:, LabelIndex) = Ddavid_recover_single_label_SVDDandKNN(Data, TrueLabel(:, LabelIndex), SampledTrueLabel(:, LabelIndex), K, KNNList, R, T);
%            case 2
%                RecoveredTrueLabel(:, LabelIndex) = Ddavid_recover_single_label_2(Data, TrueLabel(:, LabelIndex), SampledTrueLabel(:, LabelIndex), K, KNNList, R, T);
        end
    end
    disp(' ');
end

HammingLoss = Hamming_loss(RecoveredTrueLabel', TrueLabel');
